package community.hospital.util;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.LocalDateTimeUtil;
import org.springframework.util.Assert;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.Calendar;
import java.util.Date;
import java.util.Objects;

/**
 * @author yindingjie
 */
public class DateUtil {


    public static long betweenCurrentToLastDay() {
        long currentTime = System.currentTimeMillis() / 1000;
        long endTime = LocalDateTimeUtil.endOfDay(LocalDateTime.now()).atZone(ZoneId.systemDefault()).toEpochSecond();
        return currentTime - endTime;
    }

    public static Date getStartDate(Date date) {
        if (date == null) {
            return null;
        }
        Calendar instance = Calendar.getInstance();
        instance.setTime(date);
        instance.set(Calendar.HOUR_OF_DAY,0);
        instance.set(Calendar.MINUTE,0);
        instance.set(Calendar.MILLISECOND, 0);
        return instance.getTime();
    }
    public static Date getEndDate(Date date) {
        if (date == null) {
            return null;
        }
        return cn.hutool.core.date.DateUtil.endOfDay(date).toJdkDate();
    }

}
